package cn.stylefeng.guns.czlm.controller;


import cn.stylefeng.guns.core.common.annotion.BussinessLog;
import cn.stylefeng.guns.core.common.constant.dictmap.IntegralrecordMap;
import cn.stylefeng.guns.core.common.exception.BizExceptionEnum;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.czlm.entity.Integralrecord;
import cn.stylefeng.guns.czlm.service.IntegralrecordService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Integralrecord")
public class IntegralrecordController extends BaseController {
    @Autowired
    private IntegralrecordService integralrecordService;
    private static String PREFIX = "/modular/system/Integralrecord/";

    /**
     * 进入到积分信息
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping("")
    public String index() {
        System.out.println("进入页面");
        return PREFIX + "Integralrecord.html";
    }

    /**
     * 查询积分信息
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<Integralrecord> findIntegralrecordAll(String nickname){
        List<Integralrecord> ilist = this.integralrecordService.findIntegralrecordAll(nickname);
        return ilist;
    }

    /**
     * 跳转到新增页
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping("/IntegralrecordAdd")
    public String student_add_type(){return PREFIX + "IntegralrecordAdd.html"; }

    /**
     * 新增
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @BussinessLog(value = "新增通知", key = "title", dict = IntegralrecordMap.class)
    public Object add(Integralrecord ild) {
        this.integralrecordService.save(ild);
        return SUCCESS_TIP;
    }

    /**
     * 跳转到修改积分页
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/Integralrecord_update")
    public String IntegralrecordUpdate(@RequestParam Integer integralid) {
        System.out.println("进入11111");
        if (ToolUtil.isEmpty(integralid)){
            throw new RequestEmptyException();
        }
        System.out.println("进入22222");
        Integralrecord integralrecord = integralrecordService.findIntegralrecordByIds(integralid);
        LogObjectHolder.me().set(integralrecord);
        System.out.println("进入33333");
        return PREFIX + "/IntegralrecordEdit.html";
    }

    /**
     * 数据回显
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/findIldById")
    @ResponseBody
    public Object findIldById(@RequestParam Integer integralid){
        if (ToolUtil.isEmpty(integralid)){
            throw new RequestEmptyException();
        }
        Integralrecord integralrecord=this.integralrecordService.findIntegralrecordByIds(integralid);
        return integralrecord;
    }

    /**
     * 修改积分
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/edit")
    @BussinessLog(value = "修改用户", key = "integralid", dict = IntegralrecordMap.class)
    @ResponseBody
    public Object edit(Integralrecord integralrecord) {
        if (ToolUtil.isOneEmpty(integralrecord,integralrecord.getIntegralid(),integralrecord.getUserid())){
            throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
        }
        System.out.println(integralrecord);
        this.integralrecordService.updateIldById(integralrecord);
        return SUCCESS_TIP;
    }

    /**
     * 删除积分
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除积分", key = "integralid", dict = IntegralrecordMap.class)
    public Object delete(@RequestParam Integer integralid) {


        this.integralrecordService.deleteIldById(integralid);

        return SUCCESS_TIP;
    }
}
